package cn.stylefeng.guns.sys.modular.system.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.system.db4.service.TeamService;
import cn.stylefeng.guns.sys.modular.system.entity.TaskStatus;
import cn.stylefeng.guns.sys.modular.system.mapper.UserMapper;
import cn.stylefeng.guns.sys.modular.system.model.params.ProjectParam;
import cn.stylefeng.guns.sys.modular.system.model.params.TaskStatusParam;
import cn.stylefeng.guns.sys.modular.system.service.*;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/gcApp")
public class GcAppController {

    private static Logger logger = LoggerFactory.getLogger(GcAppController.class);

    @Autowired
    private ProjectService projectService;

    @Autowired
    private GcWxService gcWxService;

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private TeamService teamService;

    @Autowired
    private TaskStatusService taskStatusService;

    @Autowired
    private TaskService taskService;

    @Autowired
    private GcAppService gcAppService;


    /**
     *  本店任务列表
     * @param proId 工程id
     * @return
     */
    @ResponseBody
    @RequestMapping("/proIdList")
    public ResponseData proIdList(Integer proId) {

//        return gcWxService.proIdList(proId);
        return gcAppService.proIdList(proId);
    }

    /**
     * 新增任务信息(营运)
     *
     * @return
     */
    @ResponseBody
    @PostMapping("/addRent")
    public ResponseData addRent(@RequestBody List<TaskStatus> taskStatus) throws Exception {

//        this.gcWxService.addRent(taskStatus);
        this.gcAppService.addRent(taskStatus);
        return ResponseData.success();
    }

    /**
     * 收银系统建档
     *
     * @return
     */
    @ResponseBody
    @PostMapping("/archives")
    public ResponseData archives(@RequestBody List<TaskStatus> taskStatus) {

//        this.gcWxService.archives(taskStatus);
        this.gcAppService.archives(taskStatus);
        return ResponseData.success();
    }

    /**
     *  全部店已完成任务列表
     * @return
     */
    @ResponseBody
    @RequestMapping("/finishShop")
    public ResponseData finishShop(String account, String proName) {

//        return this.gcWxService.finishShop(wxOpenId, userId, proName);
        return this.gcAppService.finishShop(account, proName);
    }


    /**
     *  全部店未完成任务列表
     * @return
     */
    @ResponseBody
    @RequestMapping("/noFinishShop")
    public List noFinishShop(String account, String proName) {

//        return this.gcWxService.noFinishShop(wxOpenId, userId, proName);
        return this.gcAppService.noFinishShop(account, proName);
    }

    /**
     * 查看当前任务信息
     *
     * @return
     */
    @ResponseBody
    @GetMapping("/taskList")
    public ResponseData taskList(int proId, int taskId, String account) {

//        List<TaskStatus> list = this.gcWxService.taskList(proId, taskId, wxOpenId, userId);
        List<TaskStatus> list = this.gcAppService.taskList(proId, taskId, account);
        return ResponseData.success(list);
    }

    /**
     * 新增任务信息(工程)
     *
     * @return
     */
    @ResponseBody
    @PostMapping("/addPro")
    public ResponseData addPro(@RequestBody List<TaskStatus> taskStatus) throws Exception {

        this.gcWxService.addPro(taskStatus);
        return ResponseData.success();
    }


    /**
     * 查询督导列表
     *
     * @return
     */
    @GetMapping("/selectDdList")
    @ResponseBody
    public ResponseData selectDdList(Long userId) {

        String phone = userMapper.getPhone(userId);
        List list = teamService.selectDdList(phone);
        return ResponseData.success(list);
    }

    /**
     * 查询营运经理列表
     *
     * @return
     */
    @GetMapping("/selectYyjlList")
    @ResponseBody
    public ResponseData selectYyjlList() {

        List list = teamService.selectYyjlList();
        return ResponseData.success(list);
    }

    /**
     * 指定营运经理
     * @return
     */
    @ResponseBody
    @PostMapping("/saveYy")
    public ResponseData saveYy(ProjectParam record) {

        ResponseData responseData = projectService.saveGcWxyyjl(record);
        return responseData;
    }

    /**
     * 指定督导
     * @return
     */
    @ResponseBody
    @PostMapping("/saveDd")
    public ResponseData saveDd(ProjectParam record) {

        ResponseData responseData = projectService.saveGcWxDd(record);
        return responseData;
    }

    /**
     * 确认开店
     * @return
     */
    @ResponseBody
    @PostMapping("/audit")
    public ResponseData audit(TaskStatusParam taskStatusParam) {

        taskStatusParam.setTaskId(7);//营运总监确认
        taskStatusService.audit(taskStatusParam);
        return ResponseData.success();
    }


    /**
     * 修改任务信息
     *
     * @return
     */
    @ResponseBody
    @PostMapping("/editRent")
    public ResponseData editRent(@RequestBody List<TaskStatus> taskStatus) throws Exception {

        taskService.editRent(taskStatus);
        return ResponseData.success();
    }


    /**
     * 判断当前任务登录人角色
     * @param request
     * @return
     */
    @ResponseBody
    @GetMapping("/roleStatus")
    public ResponseData roleStatus(HttpServletRequest request, Integer proId, String account) {

//        Map map = this.gcWxService.roleStatus(proId, account);
        Map map = this.gcAppService.roleStatus(proId, account);
        return ResponseData.success(map);

    }

    /**
     *  全部店已完成任务列表
     * @return
     */
    @ResponseBody
    @RequestMapping("/finishList")
    public LayuiPageInfo finishList(String account, String proName) {

        return this.gcAppService.finishList(account, proName);
    }


    /**
     *  全部店未完成任务列表
     * @return
     */
    @ResponseBody
    @RequestMapping("/noFinishList")
    public LayuiPageInfo noFinishList(String account, String proName) {

        return this.gcAppService.noFinishList(account, proName);
    }

    /**
     *  全部店任务列表
     * @return
     */
    @ResponseBody
    @RequestMapping("/shopList")
    public LayuiPageInfo shopList(String account, String proName) {

        return this.gcAppService.shopList(account, proName);
    }

}
